<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Template Units For Numerical Applications</title>
<link href="TUNAstyles.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<style type="text/css">

.cabeza_cell {
  border-left: 1px solid #000000;
  border-right: 1px solid #000000;
  border-bottom: 1px solid #000000;
  border-top: 1px solid #000000;
  font-family: Arial,Helvetica,sans-serif;
  font-size: 11pt;
  background-color: #ffffff;
  font-weight: lighter;
  color: #000000;
  text-decoration: none;
}
</style>

</head><body>
<div>
<table align="center" width="640" border="0" cellspacing="2" cellpadding="5" class="border">
<tr>
 <td class="cabeza_cell"> 

  <font style="font-family: helvetica; color: #000000;" size=4>
    <font style="font-family: helvetica; color: #336699; font-weight=bold" size=5>TUNA</font> :
    <font style="font-family: helvetica; color: #336699; font-weight=bold" size=5>T</font>emplate
    <font style="font-family: helvetica; color: #336699; font-weight=bold" size=5>U</font>nits for
    <font style="font-family: helvetica; color: #336699; font-weight=bold" size=5>N</font>umerical 
    <font style="font-family: helvetica; color: #336699; font-weight=bold" size=5>A</font>pplications
 </font><br>
  
</td>
</tr>

<tr>
<td class="cabeza_cell">
 <span style="font-family: helvetica; color: #336699;">
 Documentation Ver 1.0.0 August 2011 by
 <a href="http://mmc.geofisica.unam.mx/luiggi">Luis M. de la Cruz</a> <br>
 <a href="http://mmc.geofisica.unam.mx"> GMMC </a> -
 <a href="http://www.geofisica.unam.mx/recnat/"> Depto. de Recursos Naturales </a> -
 <a href="http://www.geofisica.unam.mx"> Instituto de Geof&iacute;sica </a> -
 <a href="http://www.unam.mx"> UNAM </a><br>
 </span>
 </td>

</tr>

</table>
</div>
<br>
<!-- Generated by Doxygen 1.7.4 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">Examples/09FlowInPorousMedia/DataSingle2D/transPressure.cpp</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &quot;Meshes/Uniform.hpp&quot;</span>
<a name="l00003"></a>00003 <span class="keyword">using namespace </span>Tuna;
<a name="l00004"></a>00004 
<a name="l00005"></a>00005 <span class="keyword">typedef</span> <a class="code" href="structTuna_1_1TunaArray.html#af3bcab5018eec3d7697c9fb03ad89157" title="Definition of big arrays to store scalar fields on meshes.">TunaArray&lt;double,2&gt;::huge</a> ScalarField2D;
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="keywordtype">void</span> readFromFile_DX(ScalarField2D&amp; scf1, <span class="keywordtype">int</span> number, <span class="keywordtype">string</span> filename, <span class="keywordtype">int</span> w); 
<a name="l00008"></a>00008 <span class="keywordtype">void</span> writeToFile_Press(ScalarField2D&amp; scf, <span class="keywordtype">int</span> number, <span class="keywordtype">string</span> filename, 
<a name="l00009"></a>00009                        <span class="keywordtype">double</span> dx, <span class="keywordtype">int</span> mony, <span class="keywordtype">int</span> w); 
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="keywordtype">int</span> main() 
<a name="l00012"></a>00012 {
<a name="l00013"></a>00013   <span class="keywordtype">double</span> length_x, length_y, dt; 
<a name="l00014"></a>00014   <span class="keywordtype">int</span> num_nodes_x, num_nodes_y, frequency;
<a name="l00015"></a>00015   <span class="keywordtype">double</span> Tmax;
<a name="l00016"></a>00016 
<a name="l00017"></a>00017   std::ifstream input_cin (<span class="stringliteral">&quot;inputTransPress&quot;</span>); 
<a name="l00018"></a>00018   input_cin &gt;&gt; length_x &gt;&gt; length_y
<a name="l00019"></a>00019             &gt;&gt; num_nodes_x &gt;&gt; num_nodes_y
<a name="l00020"></a>00020             &gt;&gt; dt
<a name="l00021"></a>00021             &gt;&gt; Tmax
<a name="l00022"></a>00022             &gt;&gt; frequency;
<a name="l00023"></a>00023   input_cin.close();
<a name="l00024"></a>00024   
<a name="l00025"></a>00025   <a class="code" href="classTuna_1_1StructuredMesh.html" title="General structured meshes on rectangular domains.">StructuredMesh&lt;Uniform&lt;double, 2&gt;</a> &gt; mesh(length_x, num_nodes_x,
<a name="l00026"></a>00026                                            length_y, num_nodes_y);
<a name="l00027"></a>00027   <span class="keywordtype">double</span> dx = mesh.getDelta(X), dy = mesh.getDelta(Y);
<a name="l00028"></a>00028   ScalarField2D pn( mesh.getExtentNodes()   );
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 
<a name="l00031"></a>00031   ofstream press_fp(<span class="stringliteral">&quot;./&quot;</span>), residual_fp(<span class="stringliteral">&quot;./DataSingle2D/residual&quot;</span>);
<a name="l00032"></a>00032   <span class="keywordtype">int</span> mony = num_nodes_y / 2;
<a name="l00033"></a>00033   <span class="keywordtype">int</span> iteration = 0, pausa;
<a name="l00034"></a>00034   <span class="keywordtype">double</span> t = dt;
<a name="l00035"></a>00035   <span class="keywordflow">while</span> (t &lt;= Tmax) {
<a name="l00036"></a>00036     std::cout &lt;&lt; <span class="stringliteral">&quot;\n ---- Iteration &quot;</span> &lt;&lt; ++iteration ;
<a name="l00037"></a>00037     readFromFile_DX(pn, iteration, <span class="stringliteral">&quot;./pres.&quot;</span>, 5);
<a name="l00038"></a>00038     <span class="comment">//    cout &lt;&lt; pn; cin &gt;&gt; pausa;</span>
<a name="l00039"></a>00039     writeToFile_Press(pn, iteration, <span class="stringliteral">&quot;./pgnu.&quot;</span>, dx, mony, 5);
<a name="l00040"></a>00040     t += dt;
<a name="l00041"></a>00041   }
<a name="l00042"></a>00042   
<a name="l00043"></a>00043   <span class="keywordflow">return</span> 0; 
<a name="l00044"></a>00044 }
<a name="l00045"></a>00045 
<a name="l00046"></a>00046 <span class="keywordtype">void</span> writeToFile_Press(ScalarField2D&amp; scf, <span class="keywordtype">int</span> number, <span class="keywordtype">string</span> filename, <span class="keywordtype">double</span> dx, 
<a name="l00047"></a>00047                        <span class="keywordtype">int</span> mony, <span class="keywordtype">int</span> w) 
<a name="l00048"></a>00048 {   
<a name="l00049"></a>00049     ostringstream extnumber;
<a name="l00050"></a>00050     extnumber.width(w);
<a name="l00051"></a>00051     extnumber.fill(<span class="charliteral">&#39;0&#39;</span>);
<a name="l00052"></a>00052     extnumber &lt;&lt; number;
<a name="l00053"></a>00053     <span class="keywordtype">string</span> snumber = extnumber.str();
<a name="l00054"></a>00054     filename += snumber;
<a name="l00055"></a>00055 
<a name="l00056"></a>00056     ofstream file (filename.c_str());
<a name="l00057"></a>00057     <span class="keywordflow">if</span> (!file) {
<a name="l00058"></a>00058         cout &lt;&lt; <span class="stringliteral">&quot;\n !Can&#39;t open file \&quot; &quot;</span> &lt;&lt; filename &lt;&lt; <span class="stringliteral">&quot;\&quot;&quot;</span> &lt;&lt; endl;
<a name="l00059"></a>00059     }
<a name="l00060"></a>00060 
<a name="l00061"></a>00061     <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt;= scf.ubound(firstDim); ++i) 
<a name="l00062"></a>00062       file &lt;&lt; i * dx &lt;&lt; <span class="stringliteral">&quot;\t&quot;</span> &lt;&lt; scf(i, mony) &lt;&lt; endl;
<a name="l00063"></a>00063     <span class="comment">//      cout &lt;&lt; i * dx &lt;&lt; &quot;\t&quot; &lt;&lt; scf(i, mony) &lt;&lt; endl;</span>
<a name="l00064"></a>00064     
<a name="l00065"></a>00065     file.close();   
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067 
<a name="l00068"></a>00068 
<a name="l00069"></a>00069 <span class="keywordtype">void</span> readFromFile_DX(ScalarField2D&amp; scf1, <span class="keywordtype">int</span> number, <span class="keywordtype">string</span> filename, <span class="keywordtype">int</span> w) 
<a name="l00070"></a>00070 {   
<a name="l00071"></a>00071     ostringstream extnumber;
<a name="l00072"></a>00072     extnumber.width(w);
<a name="l00073"></a>00073     extnumber.fill(<span class="charliteral">&#39;0&#39;</span>);
<a name="l00074"></a>00074     extnumber &lt;&lt; number;
<a name="l00075"></a>00075     <span class="keywordtype">string</span> snumber = extnumber.str();
<a name="l00076"></a>00076     filename += snumber;
<a name="l00077"></a>00077     ifstream file (filename.c_str());
<a name="l00078"></a>00078 
<a name="l00079"></a>00079     <span class="keywordflow">if</span> (!file) {
<a name="l00080"></a>00080       cout &lt;&lt; <span class="stringliteral">&quot;\n !Can&#39;t open file \&quot; &quot;</span> &lt;&lt; filename &lt;&lt; <span class="stringliteral">&quot;\&quot;&quot;</span> &lt;&lt; endl;
<a name="l00081"></a>00081     }
<a name="l00082"></a>00082     
<a name="l00083"></a>00083     <span class="keywordtype">char</span> line[256];
<a name="l00087"></a>00087     <span class="keywordflow">for</span>(<span class="keywordtype">int</span> ii = 1; ii &lt;= 8; ++ii)
<a name="l00088"></a>00088         file.getline(line,256);
<a name="l00089"></a>00089     
<a name="l00090"></a>00090     file.precision(10);
<a name="l00091"></a>00091     file.setf(ios_base::fixed,ios_base::floatfield);
<a name="l00095"></a>00095     <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt;= scf1.ubound(firstDim); ++i) 
<a name="l00096"></a>00096       <span class="keywordflow">for</span>(<span class="keywordtype">int</span> j = 0; j &lt;= scf1.ubound(secondDim); ++j)
<a name="l00097"></a>00097         file &gt;&gt; scf1(i,j);
<a name="l00098"></a>00098 
<a name="l00099"></a>00099     file.close();
<a name="l00100"></a>00100 }
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr size="1">
<div align="center">
Last modification: Sun Aug 28 09:57:21 CDT 2011
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&copy; 2011 LMCS-UNAM
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Generated by <a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="top" border="0" height="25"></a> 1.6.1 </div>

